#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;

    // 使用快捷键,
    QShortcut* cur1 = new QShortcut(this);
    cur1->setKey(QKeySequence("-"));
    QShortcut* cur2 = new QShortcut(this);
    cur2->setKey(QKeySequence("="));

    connect(cur1, &QShortcut::activated, this, &Widget::addValue);
    connect(cur2, &QShortcut::activated, this, &Widget::subValue);
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText("当前值为：" + QString::number(value));
}

void Widget::addValue()
{
    int value = ui->horizontalSlider->value();
    if(value <= ui->horizontalSlider->minimum()){
        return;
    }
    ui->horizontalSlider->setValue(value-5);
}

void Widget::subValue()
{
    int value = ui->horizontalSlider->value();
    if(value >= ui->horizontalSlider->maximum()){
        return;
    }
    ui->horizontalSlider->setValue(value+5);
}
